package oh.june.kwon.custom;


import oh.june.kwon.util.DrawUtil;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.decor.Border;

public class TextBoxFieldManager extends HorizontalFieldManager {
    //Define some variables to be used
    //in the class
    private int editWidth;
    private int lblWidth;
    public int allheight;
    public EditField editField;
    private LabelField lblField;

    //Pass in the fixed height and width for our object
    public TextBoxFieldManager(String lblText,
    		String editText, 
    		int lblwidth, 
    		int textwidth,
    		int editMax,long style,
    		boolean bEditable) {
        //This call to super will help keep the object in place
        super();
        editWidth = textwidth;
        lblWidth = lblwidth; 
        allheight = getFont().getHeight();
        
        lblField = new LabelField(lblText);
        add(lblField);        
        editField = new EditField("",editText,editMax,style | EditField.FIELD_BOTTOM);
        editField.setEditable(bEditable);
        add(editField);

    };

    //Pass in the fixed height and width for our object
    public TextBoxFieldManager(String lblText,
    		String editText, 
    		int lblwidth, 
    		int textwidth,
    		int editMax,long style,
    		boolean bEditable,long sytle) {
        //This call to super will help keep the object in place
        super(sytle);
        editWidth = textwidth;
        lblWidth = lblwidth; 
        allheight = getFont().getHeight();
        
        lblField = new LabelField(lblText);
        add(lblField);        
        editField = new EditField("",editText,editMax,style | EditField.FIELD_BOTTOM);
        editField.setEditable(bEditable);
        add(editField);
    };
    
    public TextBoxFieldManager(String lblText,
    		String editText, 
    		int lblwidth, 
    		int textwidth,
    		int editMax,long style,
    		boolean bEditable,long sytle, String caculatedValue) {
        //This call to super will help keep the object in place
        super(sytle);
        editWidth = textwidth;
        lblWidth = lblwidth; 
        allheight = getFont().getHeight();
        
        lblField = new LabelField(lblText);
        add(lblField);        
        editField = new EditField("",editText,editMax,style | EditField.FIELD_BOTTOM);
        editField.setEditable(bEditable);
        add(editField);
    };
    
    public void setEditable(boolean bFlase)
    {
    	editField.setEditable(bFlase);
    }
    
    public void paint(Graphics g) {
        super.paint(g);
        //Draw a rectangle around out TextBoxField
       // g.drawRect(0, 0, getWidth(), getHeight());
    }

    //If this call to sublayout was made by the system then 
    //both parameters would be passed with a value of 0. 
    //This check and adjustment keeps the fixed properties
    //maintained.
    public void sublayout(int width, int height) {

    	this.layoutChild(lblField, lblWidth, allheight);
		this.setPositionChild(lblField, 0, 2);
		this.layoutChild(editField, editWidth, allheight);
		this.setPositionChild(editField, lblWidth + 1,2);
		
		int prefferedWidth = lblWidth + editWidth +2; 
        setExtent(prefferedWidth,allheight + 4);
    }

    protected synchronized void onFieldValueChanged(String Text){
    	
    }

    //The following two methods allows users of the
    //TextBofField read and set its contents.
    public void setText(String text) {
        editField.setText(text);
    }
    
    public String getText() {
        return editField.getText();
    }
    
    public Object Tag;
    
    public void setBorder(Border br)
    {
    	editField.setBorder(br);
    }
    public void setFontSize(int nFontSize)
    {
    	editField.setFont(  DrawUtil.getCommonFont(nFontSize)); 
    }
}
